package com.ruoyi.device.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.customer.api.factory.RemoteCustomerFallbackFactory;
import com.ruoyi.device.api.RemoteDeviceService;
import com.ruoyi.device.api.domain.DeviceOnline;
import com.ruoyi.device.api.enums.DeviceStatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

public class RemoteDeviceFallbackFactory  implements FallbackFactory<RemoteDeviceService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteCustomerFallbackFactory.class);
    @Override
    public RemoteDeviceService create(Throwable cause) {
        log.error("iot服务调用失败:{}", cause.getMessage());
        return new RemoteDeviceService() {
            @Override
            public R<Boolean> updateDeviceStatus( DeviceOnline device, String source) {
                String message=device.getIsOnline().equals(String.valueOf(DeviceStatusEnum.ON_LINE.getStatus()))?"上线": "下线";
                return R.fail("更新设备:"+device.getDeviceNo()+"___"+message+"失败:" + cause.getMessage());
            }
        };
    }
}
